package com.jrx.anytxn.transaction.controller.api;

import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import com.jrx.anytxn.param.entity.PmMerchantTable;
import com.jrx.anytxn.param.service.partner.IPmMerchantTableService;
import com.jrx.anytxn.transaction.dto.loan.QueryMerchantInfoReq;
import com.jrx.anytxn.transaction.dto.loan.QueryMerchantInfoRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @program: anytxn-cf-transaction
 * @description: 商户相关接口
 * @author: xiaoyu.jing
 * @date: 2020-04-21 14:43
 **/
@Api(tags = "商户相关接口")
@RestController
@RequestMapping(value = "/api/transaction/merchant")
public class MerchantController {

    private static final Logger logger = LoggerFactory.getLogger(MerchantController.class);

    @Autowired
    private IPmMerchantTableService merchantService;

    @ApiOperation(value = "商户信息查询", notes = "商户信息查询API")
    @PostMapping(value = "/queryMerchantInfo")
    public TxnRespResult<QueryMerchantInfoRes> queryMerchantInfo(@Valid @RequestBody QueryMerchantInfoReq queryMerchantInfoReq) throws TxnException {

        TxnRespResult<QueryMerchantInfoRes> result = new TxnRespResult<>();
        logger.debug("商户信息查询开始startTime:{}",result.getStartTime());
        PmMerchantTable pmMerchantTable = merchantService.getByMerchanId(queryMerchantInfoReq.getTenantId(),queryMerchantInfoReq.getMerchantId());
        QueryMerchantInfoRes queryMerchantInfoRes = new QueryMerchantInfoRes();
        queryMerchantInfoRes.setMerchantId(queryMerchantInfoReq.getMerchantId());
        queryMerchantInfoRes.setMerchantName(pmMerchantTable.getMerchantName());
        result.getSuccess(queryMerchantInfoRes);
        logger.debug("商户信息查询成功返回信息endTime{}",result.getEndTime());
        return result;
    }
}
